package com.apes.framework.config.dozer;

//import com.apes.framework.jpa.BaseModel;
import com.apes.framework.util.ReflectUtil;
import org.dozer.DozerEventListener;
import org.dozer.event.DozerEvent;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 功能：DozerEventListener
 *
 * @author xul
 * @create 2018-08-01 16:50
 */
@Component
public class ApesDozerEventListener implements DozerEventListener {

    @Override
    public void mappingStarted(DozerEvent event) {

    }

    @Override
    public void preWritingDestinationValue(DozerEvent event) {

    }

    @Override
    public void postWritingDestinationValue(DozerEvent event) {

    }

    @Override
    public void mappingFinished(DozerEvent event) {
//        Object sourceObject = event.getSourceObject();
//        Object destinationObject = event.getDestinationObject();
//        if (sourceObject instanceof Map && destinationObject instanceof BaseModel) { // map -> model
//            List<String> propertyNames = ReflectUtil.getPropertyName(destinationObject);
//            ((Map) sourceObject).keySet().stream().filter(k -> !(propertyNames.contains(k)
//                    || ((String) k).startsWith("taskExecutor")
//                    || ((String) k).startsWith("wfTask")
//                    || ((String) k).startsWith("wf_")
//                    || k.equals("isComplain")
//                    || k.equals("processInitiatingDepartment")
//                    || k.equals("processInitiator")
//                    || k.equals("loginUserId")
//                    || k.equals("loginUserName")
//                    || k.equals("assignee")
//                    || k.equals("candidates")
//                    || k.equals("taskId"))).forEach(k -> {
////                ((BaseModel) destinationObject).setProperty((String) k, ((Map) sourceObject).get(k)); //mapping
//            });
//        }
    }
}
